function [KA,Weights,name] = findRobustWeightsexhaustive1(TF,w,h,numparams,corrs)
%this function , given a camera center and a focal length and a series of fundamental
%matrices computes the error with respect to a fundamental matrix
%this function , given a camera center and a focal length and a series of fundamental
%matrices computes the error with respect to a fundamental matrix

plotting=0;
[m,numFs]=size(TF);
name='new weird';

funcOption='regularweighted';
normalize=0;
numtries=1;


Weights=ones(numFs,1);
      Weights=Weights/sum(Weights); % normalizing




 kstart=[w 0 w/2; 0 w h/2; 0 0 1];
 
 for j=1:numFs
    TF{1,j}=TF{1,j}/norm(TF{1,j},2);
 end


 
  for j=1:numFs
             EM=(kstart')*TF{1,j}*kstart+(kstart')*TF{1,j}*kstart+(kstart')*TF{1,j}*kstart;
              fixem(j,1)=2*(norm(EM,2));
  end
 
for i=1:5
    
    [allsols,  scrs, bestslns] =nonlinearOptimizeselfcalibnormMOD(TF, w,h, numparams ,Weights,numtries,kstart);
   
    for j=1:numFs
        G=(bestslns')*TF{1,j}*bestslns;
        s=svd(G);
        er=(s(1,1)-s(2,1));
       
  
          T2(j,1)=(er/fixem(j,1))^2;
  
      
    end
    
  
    
  t2old=T2;
  T2=T2/sum(T2);
        if(sum(sum(isnan(T2)))>0)
              Weights
              T2
              display('error found');
          end
   
    
    r=T2;
    
    s=0.7413*iqr(r(r>0));
    r=r/(s);
    Weights2=exponfunc(r); % based on median of residuals
  
    
    Weights=Weights2;
          Weights=Weights/sum(Weights); % normalizing
          
          if(sum(sum(isnan(Weights)))>0)
              Weights
              T2
              display('error found');
          end
 kstart=bestslns;
end


KA=bestslns;
end

function w = exponfunc(r)
    w = (exp(-r));
end